<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model.trim="dataForm.keywords" placeholder="订单编号" clearable></el-input>
      </el-form-item>
      <el-form-item label="起始时间">
        <el-date-picker
          v-model="dataForm.startTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="起始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker
          v-model="dataForm.endTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="
          dataForm.keywords = ''
          dataForm.startTime = ''
          dataForm.endTime = ''
          getDataList()">重置</el-button>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    <el-table
      :data="dataList"
      border
      :header-cell-style="tableHeaderColor2"
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
                    label="序号"
                    type="index"
                    width="50"
                    align="center">
                  </el-table-column>
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="ID"
        v-if="show">
      </el-table-column>
      <el-table-column
        prop="foreignOrderNo"
        header-align="center"
        align="center"
        label="订单编号">
      </el-table-column>
      <el-table-column
        prop="trueName"
        header-align="center"
        align="center"
        label="店铺名称">\
      </el-table-column>
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="店家账号/电话">
      </el-table-column>
      <el-table-column
        prop="orderStatus"
        header-align="center"
        align="center"
        label="订单状态">
        <template slot-scope="scope">
          <span v-if="scope.row.orderStatus === 0">等待骑手接单</span>
          <span v-else-if="scope.row.orderStatus === 1">配送中</span>
          <span v-else-if="scope.row.orderStatus === 2">交易完成</span>
        </template>
        <span v-if=""></span>
      </el-table-column>
      <el-table-column
        prop="deliverMoney"
        header-align="center"
        align="center"
        label="配送费用">
        <template slot-scope="scope">
          <label v-if="scope.row.deliverMoney !== null">￥ {{scope.row.deliverMoney}}</label>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="下单时间">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="320%"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="selectHandle(scope.row.id)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    </el-form>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 查看 -->
    <select-external-order v-if="selectVisible" ref="selectExternalOrder" @refreshDataList="getDataList"></select-external-order>
  </div>
</template>

<script>
  import SelectExternalOrder from './select-externalorder'
  export default {
    data () {
      return {
        dataForm: {
          keywords: '',
          startTime: '',
          endTime: '',
          foreignOrderNo: ''
        },
        show: false,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        selectVisible: false
      }
    },
    components: {
      SelectExternalOrder
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        debugger
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/external/queryExternalOrderList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'startTime': this.dataForm.startTime,
            'endTime': this.dataForm.endTime
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      selectHandle (id) {
        debugger
        this.selectVisible = true
        this.$nextTick(() => {
          this.$refs.selectExternalOrder.init(id)
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      tableHeaderColor2 ({ row, column, rowIndex, columnIndex }) {
        if (rowIndex === 0) {
          return 'background-color: #17B3A3;color: #303133;font-weight: 500;'
        }
      }
    }
  }
</script>
